home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13906 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: alterdial.uu.net!not-for-mail
  2. From: andrew kennedy <"andrew kennedy"@hlp.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Help
  5. Date: Wed, 10 Apr 1996 15:03:47 -0700
  6. Message-ID: <316C3043.A5D@hlp.com>
  7. NNTP-Posting-Host: public.hlp.com
  8. Mime-Version: 1.0
  9. Content-Type: multipart/mixed; boundary="------------66794A10240E"
  10. X-Mailer: Mozilla 2.01 (Win16; I)
  11.  
  12. This is a multi-part message in MIME format.
  13.  
  14. --------------66794A10240E
  15. Content-Type: text/plain; charset=us-ascii
  16. Content-Transfer-Encoding: 7bit
  17.  
  18. I wrote this code early in my C career, but there should be a better to
  19. do this. Can someone help.
  20.  
  21. --------------66794A10240E
  22. Content-Type: text/plain; charset=us-ascii
  23. Content-Transfer-Encoding: 7bit
  24. Content-Disposition: inline; filename="PROB"
  25.  
  26.  
  27.        if( !strchr(file_name, '.')) /*if file has no extension, take on .enc*/
  28.     {
  29.       strcpy(name1,file_name);
  30.       strcpy(name2,file_name);
  31.       strcat(name2, ".enc");
  32.     }
  33.        else
  34.     {
  35.      strcpy(name1, file_name);
  36.      strcpy(name2, file_name);
  37.      strrev(name2);          /* reverse string i.e. hello = olleh */
  38.      rev_string = strpbrk(name2,".");
  39.                 /* make rev_string contain only those */
  40.                 /* characters on right side of period */
  41.                 /* and then take off the period       */
  42.                 
  43.                 /* works ONLY with file names with    */
  44.                 /* the underscore, alphabetic and     */
  45.                 /* numeric characters                 */
  46.  
  47.      rev_string = strpbrk(rev_string,"abcdefghijklmnopqrstuvwxyz_0123456789");
  48.      strrev(rev_string);      /* reverse string again to get only */
  49.      strcpy(name2,rev_string);/* filename without it's extension  */
  50.      strcat(name2, ".enc");   /* copy .enc extension onto name2   */
  51.     }
  52.  
  53. --------------66794A10240E--
  54.  
  55.